<template>
	<div class="row"  v-loading="loading2" element-loading-text="拼命加载中" style="width: 100%;">
		<div class="col-xs-12">
			<div class="MasterTimetable">
			<div id="role-scheduling-tab">
				<el-button :plain="true" type="danger"  class="againBut" @click="againBut">重新排课</el-button>
				<span class="lookError" @click="lookError">点击查看规则冲突列表</span>
			<div class="role-tab noBorderBottom">
				<ul>
					<li class="no-before room-tab">
						<i class="icon-step3-std-yes dh"></i><i class="icon-step3-std-no"></i><router-link  :to="{ path: '/automatic/Student' }" >学生课表</router-link>
					</li>
					<li class="">
						<i class="icon-step3-teacher-yes"></i><i class="icon-step3-teacher-no"></i><router-link :to="{ path: '/automatic/Teacher' }" >教师课表</router-link>
					</li>
					<li  class="student-tab" v-if="showClassroom">
						<i class="icon-step3-class-yes"></i><i class="icon-step3-class-no"></i><router-link :to="{ path: '/automatic/Classroom' }">教室课表</router-link>
					</li>
					<li class="active">
						<i class="icon-step3-all-yes"></i><i class="icon-step3-all-no"></i><router-link   :to="{ path: '/automatic/MasterTimetable' }" >总课表</router-link>
					</li>
				</ul>
			</div>
			</div>
			<div class="block textAndBtn">
				<span class="demonstration">总课程表</span>
				<span class="wrapper export" @click="exportTable">
				    <el-button type="primary" icon="upload2">导出总课表</el-button>
				  </span>
				<div class="clear"></div>
			</div>
			<el-table :data="getAllList" align="center" border style="width: 100%" id="AllClassList">
				<el-table-column label="" width="150">
					<el-table-column prop="className" label="" class="hideTableHead">
					</el-table-column>
				</el-table-column>
				<el-table-column label="星期一" v-if="dayShow1" align="center" class="hideTableHead">
					<el-table-column v-if="show1" prop="Mon1" class="hideTableHead">
					</el-table-column>
					<el-table-column v-if="show2" prop="Mon2">
					</el-table-column>
					<el-table-column v-if="show3" prop="Mon3">
					</el-table-column>
					<el-table-column v-if="show4" prop="Mon4">
					</el-table-column>
					<el-table-column v-if="show5" prop="Mon5">
					</el-table-column>
					<el-table-column v-if="show6" prop="Mon6">
					</el-table-column>
					<el-table-column v-if="show7" prop="Mon7">
					</el-table-column>
					<el-table-column v-if="show8"  prop="Mon8">
					</el-table-column>
					<el-table-column v-if="show9"  prop="Mon9">
					</el-table-column>
					<el-table-column v-if="show10"  prop="Mon10">
					</el-table-column>
				</el-table-column>
				<el-table-column label="星期二" v-if="dayShow2" align="center" class="hideTableHead">
					<el-table-column v-if="show1" prop="Tues1">
					</el-table-column>
					<el-table-column v-if="show2" prop="Tues2">
					</el-table-column>
					<el-table-column v-if="show3" prop="Tues3">
					</el-table-column>
					<el-table-column v-if="show4" prop="Tues4">
					</el-table-column>
					<el-table-column v-if="show5" prop="Tues5">
					</el-table-column>
					<el-table-column v-if="show6" prop="Tues6">
					</el-table-column>
					<el-table-column v-if="show7" prop="Tues7">
					</el-table-column>
					<el-table-column v-if="show8" prop="Tues8">
					</el-table-column>
					<el-table-column v-if="show9" prop="Tues9">
					</el-table-column>
					<el-table-column v-if="show10" prop="Tues10">
					</el-table-column>
				</el-table-column>
				<el-table-column label="星期三" v-if="dayShow3" align="center" class="hideTableHead">
					<el-table-column v-if="show1" prop="Wednes1">
					</el-table-column>
					<el-table-column v-if="show2" prop="Wednes2">
					</el-table-column>
					<el-table-column v-if="show3" prop="Wednes3">
					</el-table-column>
					<el-table-column v-if="show4" prop="Wednes4">
					</el-table-column>
					<el-table-column v-if="show5" prop="Wednes5">
					</el-table-column>
					<el-table-column v-if="show6" prop="Wednes6">
					</el-table-column>
					<el-table-column v-if="show7" prop="Wednes7">
					</el-table-column>
					<el-table-column v-if="show8" prop="Wednes8">
					</el-table-column>
					<el-table-column v-if="show9" prop="Wednes9">
					</el-table-column>
					<el-table-column v-if="show10" prop="Wednes10">
					</el-table-column>
				</el-table-column>
				<el-table-column label="星期四" v-if="dayShow4" align="center" class="hideTableHead">
					<el-table-column v-if="show1" prop="Thurs1">
					</el-table-column>
					<el-table-column v-if="show2" prop="Thurs2">
					</el-table-column>
					<el-table-column v-if="show3" prop="Thurs3">
					</el-table-column>
					<el-table-column v-if="show4" prop="Thurs4">
					</el-table-column>
					<el-table-column v-if="show5" prop="Thurs5">
					</el-table-column>
					<el-table-column v-if="show6" prop="Thurs6">
					</el-table-column>
					<el-table-column v-if="show7" prop="Thurs7">
					</el-table-column>
					<el-table-column v-if="show8" prop="Thurs8">
					</el-table-column>
					<el-table-column v-if="show9" prop="Thurs9">
					</el-table-column>
					<el-table-column v-if="show10" prop="Thurs10">
					</el-table-column>
				</el-table-column>
				<el-table-column label="星期五" v-if="dayShow5" align="center" class="hideTableHead">
					<el-table-column v-if="show1" prop="Fri1">
					</el-table-column>
					<el-table-column v-if="show2" prop="Fri2">
					</el-table-column>
					<el-table-column v-if="show3" prop="Fri3">
					</el-table-column>
					<el-table-column v-if="show4" prop="Fri4">
					</el-table-column>
					<el-table-column v-if="show5" prop="Fri5">
					</el-table-column>
					<el-table-column v-if="show6" prop="Fri6">
					</el-table-column>
					<el-table-column v-if="show7" prop="Fri7">
					</el-table-column>
					<el-table-column v-if="show8" prop="Fri8">
					</el-table-column>
					<el-table-column v-if="show9" prop="Fri9">
					</el-table-column>
					<el-table-column v-if="show10" prop="Fri10">
					</el-table-column>
				</el-table-column>
				<el-table-column label="星期六" v-if="dayShow6" align="center" class="hideTableHead">
					<el-table-column v-if="show1" prop="Satur1">
					</el-table-column>
					<el-table-column v-if="show2" prop="Satur2">
					</el-table-column>
					<el-table-column v-if="show3" prop="Satur3">
					</el-table-column>
					<el-table-column v-if="show4" prop="Satur4">
					</el-table-column>
					<el-table-column v-if="show5" prop="Satur5">
					</el-table-column>
					<el-table-column v-if="show6" prop="Satur6">
					</el-table-column>
					<el-table-column v-if="show7" prop="Satur7">
					</el-table-column>
					<el-table-column v-if="show8" prop="Satur8">
					</el-table-column>
					<el-table-column v-if="show9" prop="Satur9">
					</el-table-column>
					<el-table-column v-if="show10" prop="Satur10">
					</el-table-column>
				</el-table-column>
				<el-table-column label="星期日" v-if="dayShow7" align="center" class="hideTableHead">
					<el-table-column v-if="show1" prop="Sun1">
					</el-table-column>
					<el-table-column v-if="show2" prop="Sun2">
					</el-table-column>
					<el-table-column v-if="show3" prop="Sun3">
					</el-table-column>
					<el-table-column v-if="show4" prop="Sun4">
					</el-table-column>
					<el-table-column v-if="show5" prop="Sun5">
					</el-table-column>
					<el-table-column v-if="show6" prop="Sun6">
					</el-table-column>
					<el-table-column v-if="show7" prop="Sun7">
					</el-table-column>
					<el-table-column v-if="show8" prop="Sun8">
					</el-table-column>
					<el-table-column v-if="show9" prop="Sun9">
					</el-table-column>
					<el-table-column v-if="show10" prop="Sun10">
					</el-table-column>
				</el-table-column>
			</el-table>
			<el-dialog title="规则冲突列表" :visible.sync="dialogTableVisible" class="dialogError" v-loading="loadingError" element-loading-text="拼命加载中" style="width: 100%;">
				<el-col :span="24">
						<div class="grid-content bg-purple">
							<div v-for="o in errorList" :key="o" class="text item">{{o}}</div>
						</div>
				</el-col>
			</el-dialog>
			</div>
		</div>
	</div>
</template>

<script>
	import utils from '@/assets/js/urlConfig.js'
	export default {
		data() {
			return {
				type: "all",
				taskId: "100",
				tnId: "23",
				getAllList: [],
				loading2:true,
				show1:false,
				show2:false,
				show3:false,
				show4:false,
				show5:false,
				show6:false,
				show7:false,
				show8:false,
				show9:false,
				show10:false,
				dayShow1:false,
				dayShow2:false,
				dayShow3:false,
				dayShow4:false,
				dayShow5:false,
				dayShow6:false,
				dayShow7:false,
				showClassroom:false,
				dialogTableVisible:false,
				errorList:[],
				loadingError:false,
			}
		},
		mounted() {
			this.getSessionData();
			this.getResult(this.type, this.taskId, this.tnId);
		},
		methods: {
			getResult(type, taskId, tnId) {
				this.$http.get(utils.UrlConfig.getAllCourse+"&taskId=" + taskId + "&tnId=" + tnId)
					.then(res => {
						res = res.data
						if(res.rtnCode === "0000000") {
							var json = {};
							var classNameArr = res.bizData.result.room.split("|");
							var teachDateArr = res.bizData.result.teachDate.split("|");
							var classScheduleArr = [];


							for(var a = 0; a < res.bizData.result.roomData.length; a++) {
								var chedule = [];
								for(var b = 0; b < res.bizData.result.roomData[a].length; b++) {

									// 展示用
									if(tnId == 66){
										res.bizData.result.roomData[a][b].length = 9;
									}else{
										res.bizData.result.roomData[a][b].length = 8;
									}

									for(var c = 0; c < res.bizData.result.roomData[a][b].length; c++) {
										chedule.push(res.bizData.result.roomData[a][b][c]);
									}
								}
								classScheduleArr.push(chedule);
							}
							for(var i = 0 ; i < classScheduleArr[0].length/teachDateArr.length ; i++){
								var str = "show"+(i+1);
								this[str] = true;
							}
							for(var i = 0 ; i < teachDateArr.length ; i++){
								var str = "dayShow"+(i+1);
								this[str] = true;
							}
							for(var i = 0; i < classScheduleArr.length; i++) {
								var json = {};
								json.className = classNameArr[i];
								for(var k = 0; k < classScheduleArr[0].length; k++) {
									if( k < classScheduleArr[0].length/teachDateArr.length){
										var num = "Mon"+((k%(classScheduleArr[0].length/teachDateArr.length))+1);
										json[num] = classScheduleArr[i][k];
									}else if(k == (classScheduleArr[0].length/teachDateArr.length) || k < classScheduleArr[0].length/teachDateArr.length*2){
										var num = "Tues"+((k%(classScheduleArr[0].length/teachDateArr.length))+1);
										json[num] = classScheduleArr[i][k];
									}else if(k == (classScheduleArr[0].length/teachDateArr.length*2) || k < classScheduleArr[0].length/teachDateArr.length*3){
										var num = "Wednes"+((k%(classScheduleArr[0].length/teachDateArr.length))+1);
										json[num] = classScheduleArr[i][k];
									}else if(k == (classScheduleArr[0].length/teachDateArr.length*3) || k < classScheduleArr[0].length/teachDateArr.length*4){
 										var num = "Thurs"+((k%(classScheduleArr[0].length/teachDateArr.length))+1);
										json[num] = classScheduleArr[i][k];
									}else if(k == (classScheduleArr[0].length/teachDateArr.length*4) || k < classScheduleArr[0].length/teachDateArr.length*5){
										var num = "Fri"+((k%(classScheduleArr[0].length/teachDateArr.length))+1);
										json[num] = classScheduleArr[i][k];
									}else if(k == (classScheduleArr[0].length/teachDateArr.length*5) || k < classScheduleArr[0].length/teachDateArr.length*6){
										var num = "Satur"+((k%(classScheduleArr[0].length/teachDateArr.length))+1);
										json[num] = classScheduleArr[i][k];
									}else if(k == (classScheduleArr[0].length/teachDateArr.length*6) || k < classScheduleArr[0].length/teachDateArr.length*7){
										var num = "Sun"+((k%(classScheduleArr[0].length/teachDateArr.length))+1);
										json[num] = classScheduleArr[i][k];
									}
								}
								this.getAllList.push(json);
								this.loading2 = false;
							}
						} else {
							this.$message.error(res.msg);
						}
					}).catch(error => {
						console.log(error)
					})
			},
			exportTable() {
				$("#AllClassList").table2excel({
                    exclude: ".noExl",
                    name: "Excel Document Name",
                    filename: "总课表",
                    exclude_img: true,
                    exclude_links: true,
                    exclude_inputs: true,
                    fileext: ".xls"
                });
			},
			getSessionData(){
				this.taskId = sessionStorage.getItem('taskId');
				this.tnId = sessionStorage.getItem('tnId');
				if(sessionStorage.getItem('classType')!= 1 || sessionStorage.getItem('gradeName')!="高一年级"){
						this.showClassroom = true
				}
			},
			againBut(){
				sessionStorage.setItem('canAgain', "1");
				this.$router.push({
					path: '../automatic/'
				});
			},
			lookError(){
				this.errorList =[];
				this.loadingError = true;
				this.dialogTableVisible = true;
				this.$http.post(utils.UrlConfig.findRule+"&taskId="+this.taskId+"&tnId="+this.tnId)
					.then(res => {
						res = res.data
						if (res.rtnCode === "0000000") {
							this.loadingError = false;
							this.errorList = res.bizData;
						} else {
								this.$message.error(res.msg);
						}
				}).catch(error => {
						console.log(error)
				})
			}
		}
	}
</script>

<style>
	.MasterTimetable .textAndBtn {
		margin: 20px 0;
	}

	.MasterTimetable .demonstration {
		font-weight: bold;
		font-size: 14px;
		line-height: 36px;
	}

	.MasterTimetable .export {
		float: right;
		width: 10%;
	}

	.MasterTimetable .clear {
		clear: both;
	}

	.MasterTimetable .el-table__header-wrapper table thead tr:nth-child(2){
		display: none !important;
	}

	.MasterTimetable	#role-scheduling-tab .role-tab ul .active a{
		color: #36c6d3;
	}

	.MasterTimetable #role-scheduling-tab .role-tab ul li a{
		color: #9B9B9B;
	}

	.againBut{
		width: 122px;
		padding: 8px 0;
		margin-bottom: 35px;
	}

	#role-scheduling-tab .lookError{
		cursor: pointer;
	}

	#role-scheduling-tab .lookError:hover{
				color: #36c6d3;
				text-decoration:underline;
	}

	#role-scheduling-tab .dialogError  .text {
		font-size: 14px;
	}

	#role-scheduling-tab .dialogError .item {
		padding: 14px;
		text-align: left;
	}
</style>
